<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>
<meta charset="UTF-8">
<title>合作商户配置</title>

<link rel="stylesheet" type="text/css"
	href="bootstrap/css/bootstrap.css">
<link rel="stylesheet" type="text/css"
	href="bootstrap/css/bootstrap-table.css">
<link rel="stylesheet" type="text/css" href="bootstrap/css/style.css">
<link rel="stylesheet" type="text/css"
	href="bootstrap/css/bootstrap-editable.css">
<link rel="stylesheet" type="text/css" href="bootstrap/css/dropzone.css">

</head>

<body>
	<div th:insert="~{header :: copy}"></div>

	<div class="panel panel-default" style="padding-top: 80px;margin-left: 50px;margin-right: 50px;border: 0px">
		<div class="panel-heading" style="background: white;">
			<font size="5px">合作商户配置</font>
		</div>
		<div class="panel-body">
			<div id="toolbar" class="btn-group">
				<button id="btn_add" type="button" class="btn btn-default"
					data-toggle="modal" data-target="#addModel">
					<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>新增
				</button>
			</div>
			<table id="table"></table>
		</div>
	</div>

	<div id="addModel" class="modal fade" tabindex="-1" role="dialog"
		aria-labelledby="myModalLabel" aria-hidden="true">
		<div class="modal-dialog modal-lg">
			<div class="modal-content" style="width: 500px; align-self: center;">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-hidden="true"></button>
					<h4 class="modal-title">
						<i class="icon-pencil"></i> <span id="lblAddTitle"
							style="font-weight: bold">添加合作商户</span>
					</h4>
				</div>
				<div class="modal-body" style="text-align: center;">
					<form id='searchForm' action="apiDefine/saveOrUpdate"
						class="bs-example bs-example-form" role="form"
						style="align-self: center;">
						<div class="input-group">
							<span class="input-group-addon" style="width: 120px"><i
								class="icon-th">商家编号</i></span> <input type="text" class="form-control"
								name="partnerCode" id="partnerInfo-partnerCode" 
								onblur="validateEmptyContent('partnerInfo-partnerCode','partnerCodeMsgSpan')"
								onkeyup="validateEmptyContent('partnerInfo-partnerCode','partnerCodeMsgSpan')">
							<span class="input-group-addon" id="partnerCodeMsgSpan" style="width: 150px;border:1px; background:#FFF"></span>
						</div>
						<div class="input-group">
							<span class="input-group-addon" style="width: 120px"><i
								class="icon-th">商家名称</i></span> <input type="text" class="form-control"
								name="partnerName" id="partnerInfo-partnerName" placeholder="abc" 
								onblur="validateEmptyContent('partnerInfo-partnerName','partnerNameMsgSpan')" 
								onkeyup="validateEmptyContent('partnerInfo-partnerName','partnerNameMsgSpan')">
							<span class="input-group-addon" id="partnerNameMsgSpan" style="width: 150px;border:1px; background:#FFF"></span>
						</div>
						<div class="input-group">
							<span class="input-group-addon text-center" style="width: 120px"><i
								class="icon-th">私钥ID</i></span> <input type="text" class=" form-control"
								name="secretId" id="partnerInfo-secretId" 
								onblur="validateLegalNumber('partnerInfo-secretId','secretIdMsgSpan')"
								onkeyup="validateLegalNumber('partnerInfo-secretId','secretIdMsgSpan')">
							<span class="input-group-addon" id="secretIdMsgSpan" style="width: 150px;border:1px; background:#FFF"></span>
						</div>
						<div class="input-group">
							<span class="input-group-addon text-center" style="width: 120px"><i
								class="icon-th">输入报文类型</i></span>
							<select id="partnerInfo-msgInType" style="height: 28px"></select>
						</div>
						<div class="input-group">
							<span class="input-group-addon text-center" style="width: 120px"><i
								class="icon-th">输出报文类型</i></span>
							<select id="partnerInfo-msgOutTpye" style="height: 28px"></select>
						</div>
						<div class="input-group">
							<span class="input-group-addon text-center" style="width: 120px"><i
								class="icon-th">是否激活</i></span>
							<select style="height: 28px" name = "isActivated" id="partnerInfo-isActivate">
								<option value="1">是</option>
								<option value="0" selected="selected">否</option>
							</select>
						</div>
					</form>
				</div>
				<div class="modal-footer">
					<input type="hidden" id="ID" name="ID" />
					<button type="submit" class="btn btn-primary"
						onclick="savePartnerInfo()" data-dismiss="modal">确定</button>
					<button type="button" class="btn green" data-dismiss="modal">取消</button>
				</div>
			</div>
		</div>
	</div>

</body>
<script src="bootstrap/js/jquery.min.js"></script>
<script src="bootstrap/js/jquery-ui.min.js"></script>
<script src="bootstrap/js/bootstrap.min.js"></script>
<script src="bootstrap/js/bootstrap-table.js"></script>
<script src="bootstrap/js/bootstrap-editable.min.js"></script>
<script src="bootstrap/js/dropzone.js"></script>
<script src="bootstrap/js/bootstrap-table-editable.js"></script>
<script src="bootstrap/js/gateway.js"></script>
<script type="text/javascript">
	function savePartnerInfo() {
		var partnerCode = $("#partnerInfo-partnerCode").val();
		var partnerName = $("#partnerInfo-partnerName").val();
		var secretId = $("#partnerInfo-secretId").val();
		var isActivate = $("#partnerInfo-isActivate").val();
		var msgInType = $("#partnerInfo-msgInType").val();
		var msgOutType = $("#partnerInfo-msgOutTpye").val();

		var data = {
		    partnerCode : partnerCode,
		    partnerName : partnerName,
		    secretId : secretId,
		    isActivate : isActivate,
		    msgInType : msgInType,
		    msgOutType : msgOutType
		}
		
		saveOrUpdateGateWayConfigurations(data, "/partnerInfo/saveOrUpdate", "add");
	}
	
	function sayHello(){
		alert('heihei')
	}
</script>
<script type="text/javascript">
	$(function() {
		$("#addModel").draggable();//为模态对话框添加拖拽

		var paramTypeArray = new Array();
		
		//加载输入输出报文类型
		$.ajax({
			type:"get",
			url:"/constants/getMessageTypes",
			async : false,
			success : function(data) {
				var types = "";
				for(var i = 0; i < data.length; i++ ) {
					paramTypeArray[i] = {value:data[i], text:data[i]};
					types += "<option value='"+ data[i] +"'>" + data[i] +"</option>";
				}
				$("#partnerInfo-msgOutTpye").append(types);
				$("#partnerInfo-msgInType").append(types);
			},
			error : function() {
				alert("输出报文类型加载失败!");
			}
		});
		
		var curRow = {};
		$('#table').bootstrapTable({
			url : '/partnerInfo/listAll',
			pagination : true,
			pageSize : 10,
			pageNumber : 1,
			search : true,
			searchAlign : "right",
			toolbar : "#toolbar",
			columns : [ {
				field : 'id',
				title : 'id'
			}, {
				field : 'partnerCode',
				title : '商户编号',
				editable : {
					type : 'text',
					title : '商户编号',
					validate : function(v) {
						if (!v)
							return '商户编号不能为空';

					}
				}
			}, {
				field : 'partnerName',
				title : '商家名称',
				editable : {
					type : 'text',
					title : '商家名称',
					validate : function(v) {
						if (!v)
							return '商家名称不能为空';

					}
				}
			}, {
				field : 'secretId',
				title : '商家私钥',
				editable : {
					type : 'text',
					title : '商家私钥',
					validate : function(v) {
						if (!v)
							return '商家私钥不能为空';

					}
				}
			},{
				field : 'msgInType',
				title : '输入报文类型',
				editable : {
                    type: 'select',
                    title: '输入报文类型',
                    source: paramTypeArray
				}
			}, {
				field : 'msgOutType',
				title : '输出报文类型',
				editable : {
                    type: 'select',
                    title: '输出报文类型',
                    source: paramTypeArray
				}
			}, {
				field : 'isActivate',
				title : '是否激活',
				editable : {
                    type: 'select',
                    title: '是否激活',
                    source:[{value:"1",text:"是"},{value:"0",text:"否"}]
				}
			}, {
				field : 'formatCreateTime',
				title : '创建时间'
			}, {
				field : 'formatUpdateTime',
				title : '修改时间'
			} ],
			onClickRow : function(row, $element) {
				curRow = row;
			},
			onEditableSave : function(field, row, oldValue, $el) {
				var data = {
				    id:row.id,
				    partnerCode : row.partnerCode,
				    partnerName : row.partnerName,
				    secretId : row.secretId,
				    isActivate : row.isActivate,
				    msgInType : row.msgInType,
				    msgOutType : row.msgOutType
				}
				saveOrUpdateGateWayConfigurations(data, "/partnerInfo/saveOrUpdate", "update");

			}
		});
	});
</script>

</html>